import json
import os

with open('wechat.txt', 'r', encoding='utf-8') as file:
    data = json.load(file)

separator = '"""\n'

result = ''

for qa in data:
    result += f'question: "{qa["question"]}",\nanswer: "{qa["answer"]}"\n{separator}'

result = result.rstrip(separator)

output_folder = 'wechat2'
output_file = os.path.join(output_folder, 'QA.txt')

# 确保输出文件夹存在
os.makedirs(output_folder, exist_ok=True)

with open(output_file, 'w', encoding='utf-8') as outfile:
    outfile.write(result)

print(f"保存的文件路径为： {output_file}")
